package vn.com.fsoft.action;

import java.util.List;

import vn.com.fsoft.business.IReferenceDataBussiness;
import vn.com.fsoft.business.impl.ReferenceDataBussiness;
import vn.com.fsoft.model.entities.ReferenceData;

import com.opensymphony.xwork2.ActionSupport;

public class ReferenceDataAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1791155290134174139L;
	private static IReferenceDataBussiness rBussiness;
	public ReferenceDataAction() {
		rBussiness= new ReferenceDataBussiness();		
	}

	@Override
	public String execute() throws Exception {		
		if(currentPage==1) {
			previewPage = totalPage;
			nextPage = currentPage + 1;
		} else if(currentPage > totalPage){
			currentPage = 1;
		} else  if(currentPage < totalPage && currentPage > 1) {
			previewPage = currentPage - 1;
			nextPage = currentPage + 1;
		} else if( currentPage == totalPage) {
			previewPage = nextPage = 1;
		}		
		listReferenceData = rBussiness.lookUpBussiness(bussinessName, sicCode,
				pageSize, currentPage);
		totalPage = rBussiness.getTotalPage();
		return SUCCESS;
	}

	/* Getter && setter */
	private String sicCode = "";
	private String bussinessName = "";
	private List<ReferenceData> listReferenceData;
	private static int pageSize = 5;
	private static int currentPage=1;
	private static int nextPage;
	private static int previewPage;
	private static int totalPage;
	
	public String getSicCode() {
		return sicCode;
	}

	public void setSicCode(String sicCode) {
		this.sicCode = sicCode;
	}
	public String getBussinessName() {
		return bussinessName;
	}

	public void setBussinessName(String bussinessName) {
		this.bussinessName = bussinessName;
	}

	public List<ReferenceData> getListReferenceData() {
		return listReferenceData;
	}

	public void setListReferenceData(List<ReferenceData> listReferenceData) {
		this.listReferenceData = listReferenceData;
	}

	public int getPageSize() {
		return pageSize;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getNextPage() {
		return nextPage;
	}

	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}

	public int getPreviewPage() {
		return previewPage;
	}

	public void setPreviewPage(int previewPage) {
		this.previewPage = previewPage;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public void setPageSize(int pageSize) {
		if(pageSize>0)
			this.pageSize = pageSize;
	}

}
